package com.kdtech.analyse.outside;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.analyse.AnalyseNews;
import com.kdtech.analyse.JSoupUtils;
import com.kdtech.crawler.CrawlHTML;

import com.kdtech.crawler.at.UrlArgumentTop;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;

/**
 * 生命季刊
 * @author KK
 *
 */
public class CclifeflAnalyse implements AnalyseNews {

	private static final String[] regex={
		"https://www.cclifefl.org/View/Article/[0-9]*",
	};

	
	public boolean isDetailPage(String url) {
		return RegexUtils.matchAnyIgnoreCase(url, regex);
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta news=new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt=urlMeta.getHtml();
		String url=urlMeta.getUrl();

		news.setUrl(url);
		String title=null;
		String content=null;
		String author=null;
		Long date=null;
		Document doc=Jsoup.parse(htmltxt);
		title =doc.select("th[style=font-size: 24px;]").text();
//		System.out.println(doc.select("[style*=font-size: 13px; text-align: center]").text());
		date =DateUtils.matchDate(doc.select("table[style*=width: 90%; margin: auto]").text());
		if(date==null){
			date =DateUtils.matchDate(StringUtils.substringBefore(content, "读者:"));
		}
		content=HtmlCleaner.getContentHtml(url,doc.select("table[style=width: 90%; margin: auto]"));
		news.setTitle(StringUtils.trimSpace(title));
		news.setContent(content);
		news.setAuthor(author);
		news.setDate(date);

		return news;
	}

	

	

	
}
